/**
 *
 */
package com.wedroid.r2d2.message;

import java.util.Date;

import org.apache.commons.lang3.RandomStringUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.wedroid.entity.message.MessageType;

/**
 * @author lute
 */
public class SendingMsg {

    @JSONField(name = "ClientMsgId")
    private String clientMsgId;

    @JSONField(name = "Content")
    private String content;

    @JSONField(name = "FromUserName")
    private String fromUserName;

    @JSONField(name = "LocalID")
    private String localId;

    @JSONField(name = "ToUserName")
    private String toUserName;

    @JSONField(name = "Type")
    private int type;

    @JSONField(serialize = false)
    private MessageType messageType;

    @JSONField(name = "MediaId")
    private String mediaId;

    /**
     * @param content
     * @param fromUserName
     * @param toUserName
     * @param messageType
     */
    private SendingMsg(String content, String fromUserName, String toUserName, MessageType messageType) {
        this.content = content;
        this.fromUserName = fromUserName;
        this.toUserName = toUserName;
        this.clientMsgId = String.valueOf(new Date().getTime()) + RandomStringUtils.randomNumeric(4);
        this.localId = this.clientMsgId;
        this.messageType = messageType;
        this.type = messageType.getCode();
    }

    /**
     * @param content
     * @param fromUserName
     * @param toUserName
     */
    public static SendingMsg ofTextMessage(String content, String fromUserName, String toUserName) {
        return new SendingMsg(content, fromUserName, toUserName, MessageType.TEXT);
    }

    /**
     * @param mediaId
     * @param fromUserName
     * @param toUserName
     * @return
     */
    public static SendingMsg ofImageMessage(String mediaId, String fromUserName, String toUserName) {
        SendingMsg sendingMsg = new SendingMsg(null, fromUserName, toUserName, MessageType.IMAGE);
        sendingMsg.mediaId = mediaId;
        return sendingMsg;
    }

    /**
     * @param mediaId
     * @param fromUserName
     * @param toUserName
     * @return
     */
    public static SendingMsg ofEmoticonMessage(String mediaId, String fromUserName, String toUserName) {
        SendingMsg sendingMsg = new SendingMsg(null, fromUserName, toUserName, MessageType.EMOTICON);
        sendingMsg.mediaId = mediaId;
        return sendingMsg;
    }

    /**
     * @return the clientMsgId
     */
    public String getClientMsgId() {
        return clientMsgId;
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * @return the fromUserName
     */
    public String getFromUserName() {
        return fromUserName;
    }

    /**
     * @return the localId
     */
    public String getLocalId() {
        return localId;
    }

    /**
     * @return the toUserName
     */
    public String getToUserName() {
        return toUserName;
    }

    /**
     * @return the type
     */
    public int getType() {
        return type;
    }

    /**
     * @return the messageType
     */
    public MessageType getMessageType() {
        return messageType;
    }

    /**
     * @return the mediaId
     */
    public String getMediaId() {
        return mediaId;
    }

}
